import numpy as np
import networkx as nx
import pickle, os, time, sys
from scipy.linalg import lstsq

def generate_data(n, m):
    Q = np.random.randn(n, m)
    y = np.random.randn(n)
    t1 = time.time()
    #x_std = lstsq(Q, y, lapack_driver = 'gelsy')[0]
    x_std = np.linalg.lstsq(Q, y, rcond=None)[0]
    t2 = time.time()
    t_std = t2 - t1
    print(f"标准解用时{t_std}s.")
    os.makedirs(os.path.dirname("./Data/Prob/Q.txt"), exist_ok=True)
    np.savetxt("Data/Prob/Q.txt", Q, fmt='%.8f', delimiter=',')
    os.makedirs(os.path.dirname("./Data/Prob/y.txt"), exist_ok=True)
    np.savetxt("Data/Prob/y.txt", y, fmt='%.8f', delimiter=',')
    os.makedirs(os.path.dirname("./Data/Sol/x_std.txt"), exist_ok=True)
    np.savetxt("./Data/Sol/x_std.txt", x_std, fmt='%.8f', delimiter=',')
    f = open("Data/Sol/t_std.txt", "w")
    f.write(f"{t_std}")
    f.close()

if __name__ == "__main__":
    #	matrix_height = int(sys.argv[1])
    #	matrix_width = int(sys.argv[2])
    generate_data(60, 60)
